//
// Created by Administrator on 2022/1/30.
//

#ifndef CPP_LEARNING_LEETCODE349_H
#define CPP_LEARNING_LEETCODE349_H

#include <vector>
using namespace std;
#include <math.h>
#include <iostream>

#include <unordered_set>
class Solution202 {
public:
    int getSum(int n){
        int sum = 0;

        while(n> 0){
            sum += (n%10) * (n%10);
            n = n / 10;
        }

        return sum;
    }
    bool isHappy(int n) {
        unordered_set<int> set;
        int sum = getSum(n);
        while (sum != 1){
            if(set.find(sum) != set.end()){
                // 出现了死循环
                return false;
            }else{
                set.insert(sum);
            }

            sum = getSum(sum);
        }
        return true;
    }
};


void test202(){
    Solution202 s;

    std::cout<<s.isHappy(19)<<std::endl;
}
#endif //CPP_LEARNING_LEETCODE349_H
